﻿define(function (require, exports, module) {
    var uu=null;
    if (!window.uu) {

        window.uu = function () {
            return uu._impl.apply(this, arguments);
        };
        window.uu.mix = function (D, A, C) {
            for (var B in A) {
                D[B] = A[B];
            }
            return C ? uu.mix(D, C) : D;
        };
        window.uu.mix.param = function (D, A, C) {
            for (var B in A) {
                !(B in D) && (D[B] = A[B]);
            }
            return C ? uu.mix.param(D, C) : D;
        };
        window.uuClass = {};
        window.uuConst = {};
    }
    uu = window.uu;
    if (!uuClass.Color) {
        uuClass.Color = function (D, C, A, B) {
            this.construct.apply(this, arguments);
        };
        uu.color = function (D, C, A, B) {
            return new uuClass.Color(D, C, A, B);
        };
        uuClass.ColorDictionary = function () {
            var B = this,
		A = arguments.callee;
            if (!A.instance) {
                A.instance = B;
                B.construct.apply(B, arguments);
            }
            return A.instance;
        }; (function () {
            var H = parseInt,
		E = parseFloat,
		C = Math.round,
		A = uuClass.Color,
		K, I = "000000black,888888gray,ccccccsilver,ffffffwhite,ff0000red,ffff00yellow,00ff00lime,00ffffaqua,00ffffcyan,0000ffblue,ff00fffuchsia,ff00ffmagenta,880000maroon,888800olive,008800green,008888teal,000088navy,880088purple,696969dimgray,808080gray,a9a9a9darkgray,c0c0c0silver,d3d3d3lightgrey,dcdcdcgainsboro,f5f5f5whitesmoke,fffafasnow,708090slategray,778899lightslategray,b0c4delightsteelblue,4682b4steelblue,5f9ea0cadetblue,4b0082indigo,483d8bdarkslateblue,6a5acdslateblue,7b68eemediumslateblue,9370dbmediumpurple,f8f8ffghostwhite,00008bdarkblue,0000cdmediumblue,4169e1royalblue,1e90ffdodgerblue,6495edcornflowerblue,87cefalightskyblue,add8e6lightblue,f0f8ffaliceblue,191970midnightblue,00bfffdeepskyblue,87ceebskyblue,b0e0e6powderblue,2f4f4fdarkslategray,00ced1darkturquoise,afeeeepaleturquoise,f0ffffazure,008b8bdarkcyan,20b2aalightseagreen,48d1ccmediumturquoise,40e0d0turquoise,7fffd4aquamarine,e0fffflightcyan,00fa9amediumspringgreen,7cfc00lawngreen,00ff7fspringgreen,7fff00chartreuse,adff2fgreenyellow,2e8b57seagreen,3cb371mediumseagreen,66cdaamediumaquamarine,98fb98palegreen,f5fffamintcream,006400darkgreen,228b22forestgreen,32cd32limegreen,90ee90lightgreen,f0fff0honeydew,556b2fdarkolivegreen,6b8e23olivedrab,9acd32yellowgreen,8fbc8fdarkseagreen,9400d3darkviolet,8a2be2blueviolet,dda0ddplum,d8bfd8thistle,8b008bdarkmagenta,9932ccdarkorchid,ba55d3mediumorchid,da70d6orchid,ee82eeviolet,e6e6falavender,c71585mediumvioletred,bc8f8frosybrown,ff69b4hotpink,ffc0cbpink,ffe4e1mistyrose,ff1493deeppink,db7093palevioletred,e9967adarksalmon,ffb6c1lightpink,fff0f5lavenderblush,cd5c5cindianred,f08080lightcoral,f4a460sandybrown,fff5eeseashell,dc143ccrimson,ff6347tomato,ff7f50coral,fa8072salmon,ffa07alightsalmon,ffdab9peachpuff,ffffe0lightyellow,b22222firebrick,ff4500orangered,ff8c00darkorange,ffa500orange,ffd700gold,fafad2lightgoldenrodyellow,8b0000darkred,a52a2abrown,a0522dsienna,b8860bdarkgoldenrod,daa520goldenrod,deb887burlywood,f0e68ckhaki,fffacdlemonchiffon,d2691echocolate,cd853fperu,bdb76bdarkkhaki,bdb76btan,eee8aapalegoldenrod,f5f5dcbeige,ffdeadnavajowhite,ffe4b5moccasin,ffe4c4bisque,ffebcdblanchedalmond,ffefd5papayawhip,fff8dccornsilk,f5deb3wheat,faebd7antiquewhite,faf0e6linen,fdf5e6oldlace,fffaf0floralwhite,fffff0ivory",
		G = {
		    ZERO: {
		        r: 0,
		        g: 0,
		        b: 0,
		        a: 0
		    },
		    BLACK: {
		        r: 0,
		        g: 0,
		        b: 0,
		        a: 1
		    },
		    WHITE: {
		        r: 255,
		        g: 255,
		        b: 255,
		        a: 1
		    }
		},
		B = {
		    RGBAHash: function (L) {
		        return L;
		    },
		    HEX: function (M) {
		        var L = K.dec2hex;
		        return ["#", L[M.r], L[M.g], L[M.b]].join("");
		    },
		    RGB: function (L) {
		        return "rgb(" + [L.r, L.g, L.b].join(",") + ")";
		    },
		    RGBA: function (L) {
		        return "rgba(" + [L.r, L.g, L.b, L.a].join(",") + ")";
		    },
		    HSVA: function (M) {
		        var L = A._rgba2hsva(M);
		        return "hsva(" + [((L.h * 100) | 0) / 100, ((L.s * 100) | 0) / 100, ((L.v * 100) | 0) / 100, L.a].join(",") + ")";
		    },
		    HSLA: function (M) {
		        var L = A._rgba2hsla(M);
		        return "hsla(" + [((L.h * 100) | 0) / 100, ((L.s * 100) | 0) / 100, ((L.l * 100) | 0) / 100, L.a].join(",") + ")";
		    }
		},
		J = /^#(([\da-f])([\da-f])([\da-f]))(([\da-f])([\da-f]{2}))?$/,
		F = /(rgb[a]?)\s*\(\s*([0-9a-f\.%]+)\s*,\s*([0-9a-f\.%]+)\s*,\s*([0-9a-f\.%]+)(?:\s*,\s*([0-9\.]+))?\s*\)/,
		D = {
		    number: 1,
		    string: 2
		};
            uuClass.ColorDictionary.prototype = {
                construct: function () {
                    this.name2hash = {};
                    this.dec2hex = Array(256);
                    this.hex2dec = Array(256);
                    this.hexAlphaCache = {};
                    this.hexAlphaCacheCount = 0;
                    var O, N, L, S, R, M, Q, P, T = I.split(",");
                    for (O = 0; O < 16; ++O) {
                        for (N = 0; N < 16; ++N) {
                            Q = O * 16 + N;
                            P = O.toString(16) + N.toString(16);
                            this.dec2hex[Q] = P;
                            this.hex2dec[P] = Q;
                        }
                    }
                    for (O = 0, L = T.length; O < L; ++O) {
                        S = T[O];
                        R = S.substring(0, 6);
                        M = S.substring(6);
                        this.name2hash[M] = {
                            rgba: A._toRGBAHash(H(R, 16), 1),
                            hex: "#" + R
                        };
                    }
                    this.name2hash.transparent = {
                        rgba: A._toRGBAHash(0, 0),
                        hex: "#000000"
                    };
                },
                addColor: function (L) {
                    var Q = (L.toLowerCase().replace(/^[\s;]*|[\s;]*$/g, "")).split(";"),
				M,
				O,
				N = 0,
				P = Q.length;
                    for (; N < P; ++N) {
                        M = Q[N].split(":");
                        O = A._hash(M[1]);
                        this.name2hash[M[0]] = {
                            rgba: O,
                            hex: B.HEX(O)
                        };
                    }
                },
                clearCache: function (L) {
                    if (this.hexAlphaCacheCount > L) {
                        this.hexAlphaCache = {};
                        this.hexAlphaCacheCount = 0;
                    }
                }
            };
            uuClass.Color.prototype = {
                construct: function (O, N, L, M) {
                    this._lock = 0;
                    this._stack = [];
                    this.push(O, N, L, M);
                },
                push: function (P, O, L, M) {
                    var S, N, R, Q;
                    if (P !== void 0) {
                        if (P instanceof A) {
                            for (N = 0, R = P._stack.length; N < R; ++N) {
                                this._stack.push(uu.mix({},
							P._stack[N]));
                            }
                        } else {
                            if (P instanceof Array) {
                                for (N = 0, R = P.length; N < R; ++N) {
                                    if ((S = A._hash(P[N]))) {
                                        this._stack.push(S);
                                    }
                                }
                            } else {
                                if (typeof P === "string" && P.indexOf(";") > -1) {
                                    Q = (P.toLowerCase().replace(/^[\s;]*|[\s;]*$/g, "")).split(";");
                                    for (N = 0, R = Q.length; N < R; ++N) {
                                        if ((S = A._hash(Q[N]))) {
                                            this._stack.push(S);
                                        }
                                    }
                                } else {
                                    if ((S = A._hash(P, O, L, M))) {
                                        this._stack.push(S);
                                    }
                                }
                            }
                        }
                    }
                    return this;
                },
                pop: function (L) {
                    this.unlock();
                    var M = L || "RGBAHash",
				N = this._stack.pop() || G.ZERO;
                    return B[M](N);
                },
                clear: function () {
                    this._stack = [];
                    return this.unlock();
                },
                size: function () {
                    return this._stack.length;
                },
                empty: function () {
                    return !this._stack.length;
                },
                top: function () {
                    return this.ref(this._stack.length - 1);
                },
                bottom: function () {
                    return this.ref(0);
                },
                ref: function (L) {
                    return this._stack[this._ref(L)] || G.ZERO;
                },
                _ref: function (L) {
                    if (L !== void 0) {
                        return L;
                    }
                    if (this._lock) {
                        return this._lock - 1;
                    }
                    if (this._stack.length) {
                        return this._stack.length - 1;
                    }
                    return 0;
                },
                copy: function (L) {
                    this._stack.push(this.ref(L));
                    return this;
                },
                lock: function () {
                    this._lock = this._stack.length;
                    return this;
                },
                unlock: function () {
                    this._lock = 0;
                    return this;
                },
                forEach: function (P, Q, M) {
                    var N, O = 0,
				S = this._stack.length,
				L = M === void 0,
				R = B[M || "RGBAHash"];
                    for (; O < S; ++O) {
                        N = L ? this._stack[O] : R(this._stack[O]);
                        P.call(Q, N, O, this);
                    }
                    return this;
                },
                hexEach: function (L, M) {
                    return this.forEach(L, M, "HEX");
                },
                rgbaEach: function (L, M) {
                    return this.forEach(L, M, "RGBA");
                },
                zero: function () {
                    this._stack.push(G.ZERO);
                    return this;
                },
                black: function () {
                    this._stack.push(G.BLACK);
                    return this;
                },
                white: function () {
                    this._stack.push(G.WHITE);
                    return this;
                },
                hex: function (L) {
                    return B.HEX(this.ref(L));
                },
                rgb: function (L) {
                    return B.RGB(this.ref(L));
                },
                rgba: function (L) {
                    return B.RGBA(this.ref(L));
                },
                hsva: function (L) {
                    return B.HSVA(this.ref(L));
                },
                hsla: function (L) {
                    return B.HSLA(this.ref(L));
                },
                toString: function () {
                    return this.hex();
                },
                tone: function (N, M, L) {
                    if (!N && !M && !L) {
                        return this.copy();
                    }
                    var O = A._rgba2hsva(this.ref());
                    O.h += N,
				O.h = (O.h > 360) ? O.h - 360 : (O.h < 0) ? O.h + 360 : O.h;
                    O.s += M,
				O.s = (O.s > 100) ? 100 : (O.s < 0) ? 0 : O.s;
                    O.v += L,
				O.v = (O.v > 100) ? 100 : (O.v < 0) ? 0 : O.v;
                    this._stack.push(A._hsva2rgba(O));
                    return this;
                },
                complementary: function () {
                    var L = this.ref();
                    this._stack.push({
                        r: L.r ^ 255,
                        g: L.g ^ 255,
                        b: L.b ^ 255,
                        a: L.a
                    });
                    return this;
                },
                gray: function () {
                    var L = this.ref();
                    this._stack.push({
                        r: L.g,
                        g: L.g,
                        b: L.g,
                        a: L.a
                    });
                    return this;
                },
                sepia: function () {
                    var O = this.ref(),
				S,
				Q = O.r,
				P = O.g,
				L = O.b,
				R = 0.299 * Q + 0.587 * P + 0.114 * L,
				N = -0.091,
				M = 0.056;
                    Q = R + 1.4026 * M;
                    P = R - 0.3444 * N - 0.7114 * M;
                    L = R + 1.733 * N;
                    Q *= 1.2;
                    L *= 0.8;
                    Q = Q < 0 ? 0 : Q > 255 ? 255 : Q;
                    P = P < 0 ? 0 : P > 255 ? 255 : P;
                    L = L < 0 ? 0 : L > 255 ? 255 : L;
                    S = {
                        r: Q | 0,
                        g: P | 0,
                        b: L | 0,
                        a: O.a
                    };
                    this._stack.push(S);
                    return this;
                }
            };
            uu.mix(uuClass.Color, {
                _toDec: function (M) {
                    var L = (M.lastIndexOf("%") === -1) ? H(M) : (E(M) * 255 / 100) | 0;
                    return L > 255 ? 255 : L;
                },
                _toRGBAHash: function (M, L) {
                    return {
                        r: (M >> 16) & 255,
                        g: (M >> 8) & 255,
                        b: M & 255,
                        a: L
                    };
                },
                _hash: function (L, O, Q, R) {
                    if (L === void 0 || L === null) {
                        return 0;
                    }
                    var M, P = D[typeof L] || 0,
				T = K.name2hash,
				S = K.hex2dec,
				N = A._toDec;
                    if (P === 1) {
                        return (O === void 0) ? this._toRGBAHash(L, 1) : {
                            r: L,
                            g: O,
                            b: Q,
                            a: (R === void 0) ? 1 : R
                        };
                    } else {
                        if (P === 2) {
                            L = L.toLowerCase();
                            if (L in T) {
                                return T[L].rgba;
                            }
                            if ((M = L.match(J))) {
                                return (L.length > 4) ? {
                                    r: S[M[2] + M[3]],
                                    g: S[M[4] + M[6]],
                                    b: S[M[7]],
                                    a: 1
                                } : {
                                    r: S[M[2] + M[2]],
                                    g: S[M[3] + M[3]],
                                    b: S[M[4] + M[4]],
                                    a: 1
                                };
                            }
                            if ((M = L.match(F))) {
                                return {
                                    r: N(M[2]),
                                    g: N(M[3]),
                                    b: N(M[4]),
                                    a: M[1] === "rgba" ? E(M[5]) : 1
                                };
                            }
                        } else {
                            if ("r" in L) {
                                return uu.mix({},
							L);
                            }
                            if ("v" in L) {
                                return A._hsva2rgba(L);
                            }
                            if ("l" in L) {
                                return A._hsla2rgba(L);
                            }
                        }
                    }
                    return 0;
                },
                _hexAlpha: function (O) {
                    var M, R, N, T, S, P, L = K.hexAlphaCache,
				Q = K;
                    if ((D[typeof O] || 0) === 2) {
                        if (O in L) {
                            return L[O];
                        }
                        T = Q.name2hash;
                        R = O.toLowerCase();
                        if (R in T) {
                            N = T[R];
                            M = [N.hex, N.rgba.a];
                        } else {
                            if ((N = R.match(J))) {
                                M = (R.length > 4) ? [R, 1] : [["#", N[2], N[2], N[3], N[3], N[4], N[4]].join(""), 1];
                            } else {
                                if ((N = R.match(F))) {
                                    S = Q.dec2hex,
								P = A._toDec;
                                    M = [["#", S[P(N[2])], S[P(N[3])], S[P(N[4])]].join(""), N[1] === "rgba" ? E(N[5]) : 1];
                                } else {
                                    M = ["#000000", 0];
                                }
                            }
                        }
                        Q.hexAlphaCache[O] = M; ++Q.hexAlphaCacheCount;
                    } else {
                        M = ["#000000", 0];
                    }
                    return M;
                },
                _rgba2hsva: function (M) {
                    var L = M.r / 255,
				O = M.g / 255,
				P = M.b / 255,
				Q = Math.max(L, O, P),
				R = Q - Math.min(L, O, P),
				N = 0,
				T = Q ? C(R / Q * 100) : 0,
				S = C(Q * 100);
                    if (!T) {
                        return {
                            h: 0,
                            s: 0,
                            v: S,
                            a: M.a
                        };
                    }
                    N = (L === Q) ? ((O - P) * 60 / R) : (O === Q) ? ((P - L) * 60 / R + 120) : ((L - O) * 60 / R + 240);
                    return {
                        h: (N < 0) ? N + 360 : N,
                        s: T,
                        v: S,
                        a: M.a
                    };
                },
                _hsva2rgba: function (N) {
                    var L = (N.h === 360) ? 0 : N.h,
				T = N.s / 100,
				S = N.v / 100,
				R = N.a,
				P = L / 60,
				Q = P | 0,
				M = P - Q;
                    if (!T) {
                        L = C(S * 255);
                        return {
                            r: L,
                            g: L,
                            b: L,
                            a: R
                        };
                    }
                    function O() {
                        var Y = C,
					X = Y((1 - T) * S * 255),
					W = Y((1 - (T * M)) * S * 255),
					V = Y((1 - (T * (1 - M))) * S * 255),
					U = Y(S * 255);
                        switch (Q) {
                            case 0:
                                return {
                                    r:
							U,
                                    g: V,
                                    b: X,
                                    a: R
                                };
                            case 1:
                                return {
                                    r:
							W,
                                    g: U,
                                    b: X,
                                    a: R
                                };
                            case 2:
                                return {
                                    r:
							X,
                                    g: U,
                                    b: V,
                                    a: R
                                };
                            case 3:
                                return {
                                    r:
							X,
                                    g: W,
                                    b: U,
                                    a: R
                                };
                            case 4:
                                return {
                                    r:
							V,
                                    g: X,
                                    b: U,
                                    a: R
                                };
                            case 5:
                                return {
                                    r:
							U,
                                    g: X,
                                    b: W,
                                    a: R
                                };
                        }
                        return {
                            r: 0,
                            g: 0,
                            b: 0,
                            a: R
                        };
                    }
                    return O();
                },
                _rgba2hsla: function (N) {
                    var L = N.r / 255,
				Q = N.g / 255,
				R = N.b / 255,
				S = Math.max(L, Q, R),
				O = Math.min(L, Q, R),
				T = S - O,
				P = 0,
				U = 0,
				M = (O + S) / 2;
                    if (M > 0 && M < 1) {
                        U = T / (M < 0.5 ? M * 2 : 2 - (M * 2));
                    }
                    if (T > 0) {
                        if (S === L && S !== Q) {
                            P += (Q - R) / T;
                        } else {
                            if (S === Q && S !== R) {
                                P += (R - L) / T + 2;
                            } else {
                                if (S === R && S !== L) {
                                    P += (L - Q) / T + 4;
                                }
                            }
                        }
                        P *= 60;
                    }
                    return {
                        h: P,
                        s: C(U * 100),
                        l: C(M * 100),
                        a: N.a
                    };
                },
                _hsla2rgba: function (M) {
                    var Q = (M.h === 360) ? 0 : M.h,
				V = M.s / 100,
				P = M.l / 100,
				L,
				R,
				S,
				U,
				T,
				O,
				N;
                    if (Q < 120) {
                        L = (120 - Q) / 60,
					R = Q / 60,
					S = 0;
                    } else {
                        if (Q < 240) {
                            L = 0,
						R = (240 - Q) / 60,
						S = (Q - 120) / 60;
                        } else {
                            L = (Q - 240) / 60,
						R = 0,
						S = (360 - Q) / 60;
                        }
                    }
                    U = 1 - V;
                    T = V * 2;
                    L = T * (L > 1 ? 1 : L) + U;
                    R = T * (R > 1 ? 1 : R) + U;
                    S = T * (S > 1 ? 1 : S) + U;
                    if (P < 0.5) {
                        L *= P,
					R *= P,
					S *= P;
                    } else {
                        O = 1 - P;
                        N = P * 2 - 1;
                        L = O * L + N;
                        R = O * R + N;
                        S = O * S + N;
                    }
                    return {
                        r: C(L * 255),
                        g: C(R * 255),
                        b: C(S * 255),
                        a: M.a
                    };
                }
            });
            K = new uuClass.ColorDictionary();
        })();
    }
});